<template>
  <div v-if="Object.keys(userInfo).length > 0">
    <div class="user-info" :style="{background: mainColor}">
      <div class="user">
        <div class="avatar">
          <img :src="userInfo.avatar" alt="" />
        </div>
        <div class="info">
          <div class="username">
            <span class="name">{{ userInfo.nickname }}</span>
            <span class="vip-status">{{ userInfo.level.name }}</span>
            <span
              v-if="userInfo.agent"
              class="vip-status"
              style="margin-left:0.2rem;"
              >{{ userInfo.agent === 1 ? "社区代理" : "区县代理" }}</span
            >
          </div>
          <div class="other-info">
            <!-- <span v-if="userInfo.level.stop_at" class="expire"
              >有效期至{{ userInfo.level.stop_at.split(" ")[0] }}</span
            > -->
            <span class="invite">邀请码：{{ userInfo.invite_code }}</span>
            <span
              class="copy copyOrderSn"
              data-clipboard-action="copy"
              :data-clipboard-text="userInfo.invite_code"
              @click="copyLink"
              >复制</span
            >
           
          </div>
        </div>
      </div>
    </div>
    <div class="profit_option">
      <div @click="$router.push('/income-detail')" class="total_option">
        <div>{{ userInfo.sum }}</div>
        <p>总收益(元)</p>
      </div>
      <ul>
        <li @click="$router.push('/wait-to-recorded')" class="item_option">
          <p class="item_num">{{ userInfo.wait }}</p>
          <p class="item_name">待入账</p>
        </li>
        <li @click="$router.push('/balance')" class="item_option">
          <p class="item_num">{{ userInfo.wallet }}</p>
          <p class="item_name">余 额</p>
        </li>
        <li class="item_option">
          <p class="item_num">{{ userInfo.draw_money }}</p>
          <p class="item_name">已提现</p>
        </li>
        <div class="clear"></div>
      </ul>
    </div>
    <div class="profit_type">
      <ul>
        <li @click="$router.push('/recomrewards')" class="type-item">
          <img src="@/assets/vip-assets/1推荐人.png" alt="" />
          <p class="type_num">{{ userInfo.commended }}</p>
          <p class="type_name">推荐奖励(元)</p>
        </li>
        <li @click="$router.push('/shopping-reward')" class="type-item">
          <img src="@/assets/vip-assets/2购物.png" alt="" />
          <p class="type_num">{{ userInfo.commodity }}</p>
          <p class="type_name">购物收益(元)</p>
        </li>
        <li @click="$router.push('/my-team')" class="type-item">
          <img src="@/assets/vip-assets/3团队.png" alt="" />
          <p class="type_num">{{ userInfo.team }}</p>
          <p class="type_name">我的团队(个)</p>
        </li>
      </ul>
      <div class="clear"></div>
    </div>
    <a @click="$router.push('/vip-invite')" class="invite_img"
      ><img class="ad" src="@/assets/kll/yaoqing.png" alt=""
    /></a>
    <div class="profit_app">
      <ul>
        <li @click="$router.push('/my-tutor')" class="app-item">
          <img src="@/assets/vip-assets/icon1.png" alt="" />
          <p class="app_name">我的导师</p>
        </li>
        <li @click="$router.push('/business-school')" class="app-item">
          <img src="@/assets/vip-assets/icon2.png" alt="" />
          <p class="app_name">商学院</p>
        </li>
        <li @click="$router.push('/vip-equity')" class="app-item">
          <img src="@/assets/vip-assets/icon3.png" alt="" />
          <p class="app_name">VIP权益</p>
        </li>
        <div class="clear"></div>
      </ul>
    </div>
  </div>
</template>

<script>
import clipboardJs from "clipboard";
import { mapState } from 'vuex'
export default {
  props: ["userInfo"],
  data() {
    return {};
  },
  computed: {
    ...mapState({
      mainColor: state => state.app.mainColor
    })
  },
  methods: {
    copyLink() {
      let _this = this;
      let clipboard = new clipboardJs(".copyOrderSn");
      clipboard.on("success", function() {
        _this.$dialog.toast({
          mes: "复制成功",
          timeout: 1000,
          icon: "success"
        });
      });
      clipboard.on("error", function() {
        _this.$dialog.toast({
          mes: "复制失败",
          timeout: 1000,
          icon: "error"
        });
      });
    }
  }
};
</script>

<style lang="less" scoped>
.clear {
  clear: both;
}
.user-info {
  color: #f5f5f5;
  height: 6rem;
  background-color: rgb(6, 120, 255);
  padding: 0.9rem 3.2% 0.6rem;
  overflow: hidden;
  position: relative;
  .top-icon {
    width: 1.5rem;
    text-align: center;
    height: 1.24rem;
    line-height: 1.24rem;
    right: 3.2%;
    top: 0.8rem;
    position: absolute;
    .icon-dot {
      position: absolute;
      right: 0;
      top: 0;
      width: 0.28rem;
      height: 0.28rem;
      border-radius: 50%;
      background-color: red;
    }
    img {
      margin-top: 0.3rem;
      width: 55%;
    }
  }
  .user {
    display: flex;
    .avatar {
      height: 2rem;
      width: 2rem;
      border-radius: 50%;
      background: #dfdfdf;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .info {
      margin-left: 0.52rem;
      width: calc(100% - 3rem);
      .username {
        .name {
          font-size: 0.64rem;
          margin-right: 0.8rem;
          font-weight: bold;
        }
        .vip-status {
          font-size: 0.48rem;
          background: rgba(255, 255, 255, 0.2);
          display: inline-block;
          height: 0.76rem;
          border-radius: 0.38rem;
          line-height: 0.76rem;
          padding: 0 0.3rem;
        }
      }
      .other-info {
        margin-top: 0.4rem;
        font-size: 0.52rem;
        .expire {
          margin-right: 6%;
        }
        .copy {
          text-decoration: underline;
          margin-left: 3.33%;
        }
      }
    }
  }
}

.profit_option {
  position: relative;
  top: -2rem;
  left: calc(50% - 7.02rem);
  width: 14.04rem;
  background-color: #fff;
  border-radius: 0.32rem;
  padding: 1rem;
  .total_option {
    width: 100%;
    text-align: center;
    margin-bottom: 0.8rem;
  }
  .total_option div {
    font-weight: bold;
    color: #444444;
    font-size: 0.96rem;
  }
  .total_option p {
    color: #999999;
    font-size: 0.56rem;
  }
  .item_option {
    width: 33.3%;
    float: left;
    text-align: center;
    .item_num {
      color: #444444;
      font-weight: bold;
      font-size: 0.56rem;
    }
    .item_name {
      color: #999999;
      font-size: 0.56rem;
      margin-top: -0.1rem;
    }
  }
}

.profit_type {
  width: 100%;
  background: #fff;
  padding: 1rem 1rem 1.5rem;
  margin-top: -1.2rem;
  .type-item {
    width: 33.3%;
    float: left;
    text-align: center;
    height: 1.46rem;
    border-right: 2px solid #e9e9e9;
    img {
      width: 1.06rem;
      height: 1.06rem;
      margin: -0.5rem 0 0.2rem;
    }
    .type_num {
      color: #333333;
      font-size: 0.72rem;
      margin-bottom: 0.2rem;
    }
    .type_name {
      color: #999999;
      font-size: 0.52rem;
      margin-top: -0.1rem;
    }
  }
  .type-item:last-child {
    border: none;
  }
}

.profit_app {
  width: 100%;
  background: #fff;
  padding: 0.3rem 0 0.3rem;
  margin-top: 0.5rem;
  .app-item {
    width: 33.3%;
    float: left;
    text-align: center;
    padding-bottom: 0.5rem;
    img {
      width: 1.96rem;
      height: 1.96rem;
      margin: 0.5rem 0 0.2rem;
    }
    .app_name {
      color: #444444;
      font-size: 0.64rem;
    }
  }
}

.invite_img {
  width: 100%;
  display: inline-block;
  text-align: center;
  padding: 0 3.2%;
}
.ad {
  width: 100%;
}
</style>
